IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cms_sp_ModuleSelectAll]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [dbo].[cms_sp_ModuleSelectAll]
GO
create procedure [dbo].[cms_sp_ModuleSelectAll]
(
@SiteGroupId int = null,
@SiteId int = null
)
as
select
	ModuleId as Id,
	SiteGroupId,
	SiteId,
	PackageId,
	ModuleName,
	ModuleDescription,
	ModuleViewParameters,
	ModuleCommonParameters,
	CreatedBy,
	DateCreated,
	LastUpdatedBy,
	DateLastUpdated
from dbo.Modules
where ((SiteGroupId is null and SiteId is null) or 
	(SiteGroupId = @SiteGroupId and SiteId is null) or
	(SiteGroupId = @SiteGroupId and SiteId = @SiteId))


GO

